package net.web.action;

import java.util.Map;

import com.opensymphony.xwork2.ModelDriven;

import net.service.UserService;
import net.util.Tools;
import net.web.vo.Bean;

public class UserAction extends BaseAction implements ModelDriven<Bean>{
	
	public String login(){
		if(Tools.empty(request.get("username")))return ERROR;
		UserService us = new UserService();
		Map<String, Object> userinfo = us.login(bean.getUsername(), bean.getPassword());
		
		if(Tools.empty(userinfo)) return ERROR;
		session.put("user", userinfo);
		return SUCCESS;
	}
	
	/**
	 * 注册
	 * @return
	 */
	public String register(){
		if(Tools.empty(bean.getMail()) || Tools.empty(bean.getPassword())) return ERROR;
		UserService us = new UserService();
		if(us.checkUserExist(bean.getMail())){
			return ERROR;
		}
		us.register(bean.getMail(), bean.getPassword());
		return SUCCESS;
	}
	
	public String loginOut(){
		session.clear();
		return SUCCESS;
	}
	
}
